#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int n;
	cin >> n;
	vector<int> a;
	for (int i = 1; i <= n; i++)
		a.push_back(i);
	do {
		for (int ii : a)
			cout << setw(5) << ii;
		cout << endl;
	} while (next_permutation(a.begin(), a.end()));
	return 0;
}
